<template>
	<view>
		<view class="textarea">
			<u-parse :html="title"></u-parse>
			<u-parse :html="content"></u-parse>
		</view>
		<!-- <u-sticky offset-top="1100">
			<view class="">
				<u-input v-model="value" :type="type" :border="border" />
			</view>
		</u-sticky> -->
		<view class="commu">
			<text>
				<h2>评论区</h2>
			</text>
		</view>
		<view class="comment" v-for="(res, index) in commentList" :key="res.id">
			<view class="left">
				<image :src="res.url" mode="aspectFill"></image>
			</view>
			<view class="right">
				<view class="top">
					<view class="name">{{ res.name }}</view>
					<view class="like" :class="{ highlight: res.isLike }">
						<view class="num">{{ res.likeNum }}</view>
						<u-icon v-if="!res.isLike" name="thumb-up" :size="30" color="#9a9a9a" @click="getLike(index)">
						</u-icon>
						<u-icon v-if="res.isLike" name="thumb-up-fill" :size="30" @click="getLike(index)"></u-icon>
					</view>
				</view>
				<view class="content">{{ res.contentText }}</view>
				<view class="reply-box">
					<view class="item" v-for="(item, index) in res.replyList" :key="item.index">
						<view class="username">{{ item.name }}</view>
						<view class="text">{{ item.contentStr }}</view>
					</view>
					<view class="all-reply" @tap="toAllReply" v-if="res.replyList != undefined">
						共{{ res.allReply }}条回复
						<u-icon class="more" name="arrow-right" :size="26"></u-icon>
					</view>
				</view>
				<view class="bottom">
					{{ res.date }}
					<view class="reply">回复</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				commentList: [],
				content: `
			<h1>we沈理是最棒的校园论坛</h1>
				<p>沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学沈阳理工大学</p>
				<img src="https://cdn.uviewui.com/uview/swiper/2.jpg" />
				<h1>we沈理是最棒的校园论坛</h1>
			`,
			title:'',
			id:'',
			"data": {
			        "note": {
			            "oid": 6,
			            "uid": 3,
			            "otitle": "test12",
			            "opinion": "test",
			            "thumb": 2,
			            "commentNum": 3,
			            "imgPath": "opinionPhotos/090706482608ac577c113c0e15e8adc2466a8d2a240.jpg,opinionPhotos/0907064826055cd9edfca3a37b590a0dd1c5b5e4481.jpeg,",
			            "otime": "2021-09-07 18:48:26",
			            "showFlag": true,
			            "tags": "",
			            "username": "ls",
			            "headImg": "headImg/20210908043753713819.jpg"
			        },
			        "comment": [
			            {
			                "cid": 4,
			                "oid": 6,
			                "uid": 3,
			                "reactCid": -1,
			                "reactUsername": null,
			                "comment": "test",
			                "thumb": 0,
			                "imgPath": "commentPhotos/090707161508ac577c113c0e15e8adc2466a8d2a240.jpg,commentPhotos/0907071615055cd9edfca3a37b590a0dd1c5b5e4481.jpeg,",
			                "showFlag": true,
			                "ctime": "2021-09-07 19:16:15",
			                "username": "ls"
			            },
			            {
			                "cid": 5,
			                "oid": 6,
			                "uid": 3,
			                "reactCid": 4,
			                "reactUsername": null,
			                "comment": "test",
			                "thumb": 0,
			                "imgPath": " ",
			                "showFlag": true,
			                "ctime": "2021-09-09 17:59:19",
			                "username": "ls"
			            },
			            {
			                "cid": 6,
			                "oid": 6,
			                "uid": 3,
			                "reactCid": -1,
			                "reactUsername": null,
			                "comment": "test",
			                "thumb": 0,
			                "imgPath": " ",
			                "showFlag": true,
			                "ctime": "2021-09-08 19:37:51",
			                "username": "ls"
			            }
			        ]
			    },
			};
		},
		onLoad(option) {
			this.id = option.id
			let id = this.id
			console.log(id)
			this.$request({
			  method: 'GET', // 默认GET
			  url: '/v1/person/dtList',
			  data: {
				  token:uni.getStorageSync('token')
			  }
			}).then(res => {
				console.log(res.data.dt)
				// this.data.data = res.data
				this.title = res.data.dt[0].otitle
				this.content = res.data.dt[0].opinion
			  // 成功后执行，具体格式待对完接口完善
			}).catch(res => {
			  // 失败后执行
			})
		},
		methods: {
			// 跳转到全部回复
			toAllReply() {
				uni.navigateTo({
					url: '/pages/template/comment/reply'
				});
			},
			// 点赞
			getLike(index) {
				this.commentList[index].isLike = !this.commentList[index].isLike;
				if (this.commentList[index].isLike == true) {
					this.commentList[index].likeNum++;
				} else {
					this.commentList[index].likeNum--;
				}
			},
			codeChange(text) {
				this.codeText = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 1000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			// 评论列表
			getComment() {
				this.commentList = [{
						id: 1,
						name: '叶轻眉',
						date: '12-25 18:58',
						contentText: '我不信伊朗会没有后续反应，美国肯定会为今天的事情付出代价的',
						url: 'https://cdn.uviewui.com/uview/template/SmilingDog.jpg',
						allReply: 12,
						likeNum: 33,
						isLike: false,
						replyList: [{
								name: 'uview',
								contentStr: 'uview是基于uniapp的一个UI框架，代码优美简洁，宇宙超级无敌彩虹旋转好用，用它！'
							},
							{
								name: '粘粘',
								contentStr: '今天吃什么，明天吃什么，晚上吃什么，我只是一只小猫咪为什么要烦恼这么多'
							}
						]
					},
					{
						id: 2,
						name: '叶轻眉1',
						date: '01-25 13:58',
						contentText: '我不信伊朗会没有后续反应，美国肯定会为今天的事情付出代价的',
						allReply: 0,
						likeNum: 11,
						isLike: false,
						url: 'https://cdn.uviewui.com/uview/template/niannian.jpg',
					},
					{
						id: 3,
						name: '叶轻眉2',
						date: '03-25 13:58',
						contentText: '我不信伊朗会没有后续反应，美国肯定会为今天的事情付出代价的',
						allReply: 0,
						likeNum: 21,
						isLike: false,
						allReply: 2,
						url: '../../../static/logo.png',
						replyList: [{
								name: 'uview',
								contentStr: 'uview是基于uniapp的一个UI框架，代码优美简洁，宇宙超级无敌彩虹旋转好用，用它！'
							},
							{
								name: '豆包',
								contentStr: '想吃冰糖葫芦粘豆包，但没钱5555.........'
							}
						]
					},
					{
						id: 4,
						name: '叶轻眉3',
						date: '06-20 13:58',
						contentText: '我不信伊朗会没有后续反应，美国肯定会为今天的事情付出代价的',
						url: 'https://cdn.uviewui.com/uview/template/SmilingDog.jpg',
						allReply: 0,
						likeNum: 150,
						isLike: false
					}
				];
			}
		}
	};
</script>

<style lang="scss" scoped>
	.comment {
		display: flex;
		padding: 30rpx;

		.left {
			image {
				width: 64rpx;
				height: 64rpx;
				border-radius: 50%;
				background-color: #f2f2f2;
			}
		}

		.right {
			flex: 1;
			padding-left: 20rpx;
			font-size: 30rpx;

			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10rpx;

				.name {
					color: #5677fc;
				}

				.like {
					display: flex;
					align-items: center;
					color: #9a9a9a;
					font-size: 26rpx;

					.num {
						margin-right: 4rpx;
						color: #9a9a9a;
					}
				}

				.highlight {
					color: #5677fc;

					.num {
						color: #5677fc;
					}
				}
			}

			.content {
				margin-bottom: 10rpx;
			}

			.reply-box {
				background-color: rgb(242, 242, 242);
				border-radius: 12rpx;

				.item {
					padding: 20rpx;
					border-bottom: solid 2rpx $u-border-color;

					.username {
						font-size: 24rpx;
						color: #999999;
					}
				}

				.all-reply {
					padding: 20rpx;
					display: flex;
					color: #5677fc;
					align-items: center;

					.more {
						margin-left: 6rpx;
					}
				}
			}

			.bottom {
				margin-top: 20rpx;
				display: flex;
				font-size: 24rpx;
				color: #9a9a9a;

				.reply {
					color: #5677fc;
					margin-left: 10rpx;
				}
			}
		}
	}

	.textarea {
		border-radius: 10rpx;
		margin: 10rpx;
		-webkit-box-shadow: 0px 3px 3px #c8c8c8;
		-moz-box-shadow: 0px 3px 3px #c8c8c8;
		box-shadow: 0px 3px 3px #c8c8c8;
	}

	.commu {
		text-align: center;
	}

	.sticky {
		width: 750rpx;
		height: 120rpx;
		background-color: #2979ff;
		color: #fff;
		padding: 24rpx;
	}
</style>
